package com.ruoyi.sale.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sale.domain.MallBrands;
import com.ruoyi.sale.service.IMallBrandsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 品牌管理Controller
 * 
 * @author ruoyi
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/sale/brands")
public class MallBrandsController extends BaseController
{
    @Autowired
    private IMallBrandsService mallBrandsService;

    /**
     * 查询品牌管理列表
     */
    @PreAuthorize("@ss.hasPermi('sale:brands:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallBrands mallBrands)
    {
        startPage();
        List<MallBrands> list = mallBrandsService.selectMallBrandsList(mallBrands);
        return getDataTable(list);
    }

    /**
     * 导出品牌管理列表
     */
    @PreAuthorize("@ss.hasPermi('sale:brands:export')")
    @Log(title = "品牌管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallBrands mallBrands)
    {
        List<MallBrands> list = mallBrandsService.selectMallBrandsList(mallBrands);
        ExcelUtil<MallBrands> util = new ExcelUtil<MallBrands>(MallBrands.class);
        util.exportExcel(response, list, "品牌管理数据");
    }

    /**
     * 获取品牌管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('sale:brands:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mallBrandsService.selectMallBrandsById(id));
    }

    /**
     * 新增品牌管理
     */
    @PreAuthorize("@ss.hasPermi('sale:brands:add')")
    @Log(title = "品牌管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallBrands mallBrands)
    {
        return toAjax(mallBrandsService.insertMallBrands(mallBrands));
    }

    /**
     * 修改品牌管理
     */
    @PreAuthorize("@ss.hasPermi('sale:brands:edit')")
    @Log(title = "品牌管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallBrands mallBrands)
    {
        return toAjax(mallBrandsService.updateMallBrands(mallBrands));
    }

    /**
     * 删除品牌管理
     */
    @PreAuthorize("@ss.hasPermi('sale:brands:remove')")
    @Log(title = "品牌管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallBrandsService.deleteMallBrandsByIds(ids));
    }


    /**
     * 获取所有品牌
     */
    @GetMapping("/getAllBrandName")
    public AjaxResult getAllBrandName()
    {
        return success(mallBrandsService.getAllBrandName());
    }

}
